
import {HttpClient, HttpClientModule, HttpHeaders} from '@angular/common/http';

import {HttpResponse} from '@angular/common/http/src/response';

import {Observable, Observer} from 'rxjs/Rx';

import {} from 'crypto-browserify';

const PROTOCOL = 'http://';
const HOST = 'localhost';
const PORT =  ':1840';
const CONTEXT_PATH = '';


function toUrl(uri: string): string {
  return PROTOCOL + HOST + PORT + CONTEXT_PATH + uri;
}

export abstract class AbstractRemoteService {

  /**
 * 构造函数。
 * @param client Http客户端.
 */
  constructor(private client: HttpClient) {
  }

  /**
   * 发起一个post请求.
   * @param uri 请求的URI.
   * @param body 请求内容.
   */
  protected post(uri: string, body: any): Promise<any> {
    const headers = new HttpHeaders()
      .set('Content-Type', 'application/json');
    return this.client.post(toUrl(uri), body, {headers: headers}).toPromise();
  }

}
